using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Atomic.Libraries
{
	[Serializable]
	[DebuggerDisplay("Count = {Count}")]
	public class ReadOnlyDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
	{
		private Dictionary<TKey, TValue> dictionary;

		public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
		{
			this.dictionary = new Dictionary<TKey, TValue>(dictionary);
		}

		public bool ContainsKey(TKey key)
		{
			return dictionary.ContainsKey(key);
		}
		
		public bool TryGetValue(TKey key, out TValue value)
		{
			return dictionary.TryGetValue(key, out value);
		}

		public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
		{
			return dictionary.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public TValue this[TKey key]
		{
			get
			{
				return dictionary[key];
			}
		}

		public int Count
		{
			get
			{
				return dictionary.Count;
			}
		}

		public ICollection<TKey> Keys
		{
			get
			{
				// Immutable?
				return dictionary.Keys;
			}
		}

		public ICollection<TValue> Values
		{
			get
			{
				// Immutable?
				return dictionary.Values;
			}
		}
	}
}
